"""
CryptoQuant-Advisor Backend API
FastAPI application providing cryptocurrency trading analysis
"""

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles

from app.api.routes import market, strategy, sentiment, backtest
from app.core.config import settings
from app.core.database import engine, Base

# Create database tables
Base.metadata.create_all(bind=engine)

app = FastAPI(
    title="CryptoQuant-Advisor API",
    description="Advanced cryptocurrency trading analysis system",
    version="1.0.0",
    docs_url="/docs",
    redoc_url="/redoc"
)

# Configure CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=settings.ALLOWED_ORIGINS,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Include API routers
app.include_router(market.router, prefix="/api/market", tags=["market"])
app.include_router(strategy.router, prefix="/api/strategy", tags=["strategy"])
app.include_router(sentiment.router, prefix="/api/sentiment", tags=["sentiment"])
app.include_router(backtest.router, prefix="/api/backtest", tags=["backtest"])

# Health check endpoint
@app.get("/health")
async def health_check():
    return {"status": "healthy", "service": "cryptoquant-advisor"}

# Root endpoint
@app.get("/")
async def root():
    return {
        "message": "Welcome to CryptoQuant-Advisor API",
        "docs": "/docs",
        "version": "1.0.0"
    }

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(
        "app.main:app",
        host="0.0.0.0",
        port=8000,
        reload=True
    )
